package com.example.rvdemo.common.commonAdaptar;

import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

public class ViewHolder extends RecyclerView.ViewHolder {
    private SparseArray<View> mViews;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        mViews = new SparseArray<>();
    }
    public <T extends View> T getView(int viewId){
        View view = mViews.get(viewId);
        if (view == null){
            view = itemView.findViewById(viewId);
            mViews.put(viewId,view);
        }
        return (T) view;
    }

    public ViewHolder setViewVisibility(int viewId,int visivility){
        getView(viewId).setVisibility(visivility);
        return this;
    }

    public ViewHolder setImageResours(int viewId,int imgId){
        ImageView imageView = getView(viewId);
        imageView.setImageResource(imgId);
        return this;
    }
    public ViewHolder setText(int viewId, CharSequence text) {
        TextView tv = getView(viewId);
        tv.setText(text);
        return this;
    }

    public ViewHolder setImageNet(int viewId,String imgPath,HolderImageLoader imageLoader){
        ImageView imageView = getView(viewId);
        imageLoader.loadImage(imageView,imgPath);
        return this;
    }
}
